package com.lei.session.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.lei.session.dao.UserDao;
import com.lei.sqlJsp.dao.Impl.JDBC;

public class UserDaoImpl implements UserDao {

	@Override
	public boolean login(String userName, String password) {
		Connection conn = JDBC.getConn();
		String sql = "select count(1) from table_user where user_name=? and pass_word=?";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, userName);
			ps.setString(2, password);
			rs = ps.executeQuery();
			if (rs.next()) {
				return rs.getInt(1) > 0;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			JDBC.close(null, ps, conn);
		}

		return false;
	}

}
